﻿using System;
using System.Collections;

namespace TwoSum
{
  class TwoSums
  {
    // 两数之和
    public int[] TwoSumArr(int[] nums, int target)
    {
      int[] b = new int[2];
      for (int i = 0; i < nums.Length; i++)
      {
        for (int j = i + 1; j < nums.Length; j++)
        {
          if (nums[i] + nums[j] == target)
          {
            b[0] = i;
            b[1] = j;
            break;
          }
        }
      }
      return b;
    }

    // 整数反转
    public int Reverse(int x)
    {
      int br = 0;
      try
      {
        if (x > 0)
        {
          string s = x.ToString();
          char[] ch = new char[s.Length];
          for (int i = 0; i < s.Length; i++)
          {
            ch[i] = s[i];
          }
          string c = "";
          for (int j = s.Length - 1; j >= 0; j--)
          {
            c += s[j];
          }
          br = int.Parse(c);
        }
        else
        {
          x = -x;
          string s = x.ToString();
          char[] ch = new char[s.Length];
          for (int i = 0; i < s.Length; i++)
          {
            ch[i] = s[i];
          }
          string c = "";
          for (int j = s.Length - 1; j >= 0; j--)
          {
            c += s[j];
          }
          br = -int.Parse(c);
        }
      }
      catch
      { }
      return br;
    }
    // 删除排序数组中的重复项
    public int RemoveDuplicates(int[] nums)
    {
      int br = 0;
      int i = 0;
      for (int j = 1; j < nums.Length; j++)
      {
        if (nums[i] != nums[j])
        {
          i++;
          nums[i] = nums[j];
        }
      }
      if (nums.Length > 0)
      {
        br = i + 1;
      }

      return br;
    }
    //移除元素
    public int RemoveElement(int[] nums, int val)
    {
      int br = 0;
      int i = 0;
      for (int j = 0; j < nums.Length; j++)
      {
        if (nums[j] != val)
        {
          nums[i] = nums[j];
          i++;
        }
      }
      if (nums.Length > 0)
      {
        br = i;
      }
      return br;
    }

    public string ToLowerCase(string str)
    {
      str = str.ToLower();// 转为小写
      // str = str.ToUpper();// 转为大写
      return str;
    }

  }
}
